<template>
  <div class="history_pop" v-if="hisPopupShow">
    <div class="layer"></div>
    <div class="show_pop hislt">
      <div class="poptitle">
        <i @click="closeHisPopup"></i>
        <span class="fs14">历史</span>
      </div>
      <div class="contain">
        <table width="100%">
          <thead>
            <tr>
              <th>ID</th>
              <th>是否自动保存</th>
              <th>版本</th>
              <th>结果</th>
              <th>时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-show="historyList[0]" v-for="(item,index) in historyList" :key="index">
              <td>{{index + 1}}</td>
              <td>{{!!item.autoSave ? '自动' : '手动'}}</td>
              <td>{{item.version}}</td>
              <td>
                <a class="zx-op_rem-btn" @click="viewVersion(item)">查看结果</a>
              </td>
              <td width="100">{{item.createTime | toDateTime}}</td>
              <td>
                <a class="zx-op_rem-btn" @click="recoverVersion(item)">恢复到该版本</a>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
let self = null;
export default {
  name: "HistoryPop",
  data() {
    return {};
  },
  props: {
    hisPopupShow: {
      type: Boolean,
      default: false
    },
    historyList: {
      type: Array,
      default: () => []
    }
  },
  created() {
    self = this;
  },
  methods: {
    // 查看历史结果
    viewVersion(item) {
      this.$emit("viewVersion", item);
    },
    // 恢复到此历史版本
    recoverVersion(item) {
      this.$emit("recoverVersion", item);
    },
    // 关闭历史弹窗
    closeHisPopup() {
      this.$emit('closeHisPopup')
    }
  },
  filters: {
    toDateTime: function (_value) {
      // 时间转换器
      if (_value == undefined) return "--";
      return self.Utils.toDateTime(_value);
    }
  }
};
</script>

<style lang='less' scoped>
.history_pop {
  position: fixed;
  left: 0;
  top: 0;
  color: #ffaf1e;
  width: 100%;
  height: 100%;
  z-index: 999;
  .layer {
    background: rgba(0, 0, 0, 0.75);
    width: 100%;
    height: 100%;
    position: fixed;
    left: 0;
    top: 0;
  }
  .show_pop {
    width: 405px;
    text-align: left;
    display: block;
    position: fixed;
    left: 50%;
    margin-left: -202px;
    top: 50%;
    margin-top: -119px;
    background: #fff;
    overflow: hidden;
    .poptitle {
      line-height: 40px;
      height: 40px;
      border-bottom: 1px solid #e5e5e5;
      background: #f5f5f5;
    }
  }
  .hislt {
    width: 800px;
    margin-left: -400px;
    height: 374px;
    margin-top: -186px;
    .poptitle {
      color: #000;
      i {
        float: right;
        width: 12px;
        height: 12px;
        display: block;
        background: url("")
          no-repeat 0 0;
        margin-top: 14px;
        margin-right: 20px;
        cursor: pointer;
        position: static;
      }
      span {
        padding-left: 20px;
      }
    }
    .contain {
      margin: 20px;
      height: 294px;
      overflow: auto;
    }
    table {
      border: 1px solid #eee;
      border-collapse: collapse;
      tr th {
        border: 1px solid #ececec;
        background: #f5f5f5;
        height: 40px;
        padding: 0 10px;
        text-align: center;
        width: auto;
      }
      tr td {
        border: 1px solid #ececec;
        color: #333;
        height: 40px;
        padding: 0 10px;
        text-align: center;
        width: auto;
      }
      a {
        border: 1px solid #fcad1d;
        color: #fcad1d;
        overflow: initial;
        height: 25px;
        line-height: 25px;
        white-space: nowrap;
        text-overflow: ellipsis;
        text-decoration: none;
        cursor: pointer;
        user-select: none;
        background: 0 0;
        outline: 0;
        transition: color 0.2s ease;
      }
      a:hover{background:#fcad1d;color:#fff}
    }
  }
}
</style>
